﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList arrayList = new ArrayList() { "aba", "abc", "abd", "abe", "11" };
            ArrayList array = new ArrayList();

            //查找集合中是否含有abc
            Console.WriteLine("第一题");
            int index = arrayList.IndexOf("abc");
            if (index != -1)
            {
                Console.WriteLine("含有abc");
            }
            else
            {
                Console.WriteLine("不含有abc");
            }
            //查找集合中元素的个数
            Console.WriteLine(arrayList.Capacity);
            //清除集合中的所有元素
            //arrayList.Clear();
            //将集合下表元素是偶数的添加到另一个集合中；
            Console.WriteLine("第二题");
            for (int i = 0; i < arrayList.Count; i += 2)
            {
                array.Add(arrayList[i]);
            }
            foreach (var item in array)
            {
                Console.WriteLine(item);
            }
            //在一个集合中第一个元素后面任意插入三个元素；
            Console.WriteLine("第三题");
            ArrayList list = new ArrayList() { "ab", "ac", "ad" };
            arrayList.InsertRange(1, list);
            foreach (var item in arrayList)
            {
                Console.WriteLine(item);
            }
            //在集合倒数第一个元素前添加一个集合

            //arrayList.InsertRange(arrayList.Count - 1, list);
            //在集合中的元素使用sort方法排序后输出
            Console.WriteLine("第四题");
            arrayList.Sort();
            foreach (var item in arrayList)
            {
                Console.WriteLine(item);
            }
            //使用ICompare的方式来排序输出string
            Console.WriteLine("第五题");
            MyCompare myCompare = new MyCompare();
            ArrayList list1 = new ArrayList() { 11, "stre", 123, "aaf", "qqq" };
            list1.Sort(myCompare);
            foreach (var item in list1)
            {
                Console.WriteLine(item);
            }
        }
        class MyCompare : IComparer
        {
            public int Compare(object x, object y)
            {
                var str1 = x.ToString();
                var str2 = y.ToString();
                return str1.CompareTo(str2);
            }


        }
    }
}
